cmake_minimum_required(VERSION 3.10)
project(webrtc)

add_library(${PROJECT_NAME} STATIC IMPORTED GLOBAL)

# set_property(TARGET mylib2 PROPERTY IMPORTED_LOCATION mylib.dll)
set_target_properties(${PROJECT_NAME}
                      PROPERTIES
                      INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR})

target_compile_definitions(${PROJECT_NAME} INTERFACE WEBRTC_USE_BUILTIN_OPUS)

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    message("mac")

    set(PLATFORM "mac")

    target_compile_definitions(${PROJECT_NAME} INTERFACE WEBRTC_POSIX WEBRTC_MAC)
    find_library(APPLICATION_SERVICES ApplicationServices)
    find_library(AUDIO_TOOLBOX AudioToolbox)
    find_library(CORE_AUDIO CoreAudio)
    find_library(CORE_FOUNDATION Foundation)

    target_link_libraries(${PROJECT_NAME} INTERFACE
            ${APPLICATION_SERVICES}
            ${AUDIO_TOOLBOX}
            ${CORE_AUDIO}
            ${CORE_FOUNDATION})

elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    message("linux")

    set(PLATFORM "linux")


    target_compile_definitions(${PROJECT_NAME} INTERFACE WEBRTC_POSIX)
    find_package(Threads REQUIRED)

    target_link_libraries(${PROJECT_NAME} INTERFACE
            Threads::Threads)

elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
    message("win")

    set(PLATFORM "win")
else()
    message("unknown system " ${CMAKE_SYSTEM_NAME})
endif()

set_target_properties(${PROJECT_NAME}
                      PROPERTIES
                      IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/lib/${PLATFORM}/libwebrtc.a)

target_include_directories(${PROJECT_NAME} INTERFACE include
                                            include/third_party/abseil-cpp
                                            include/third_party/libjpeg_turbo
                                            include/third_party/libyuv/include)